Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: better use of autograd for base lens quantities #306

Merged
merged 13 commits into from
Jan 25, 2025

Conversation

ConnorStoneAstro
Copy link
Member

Now one need only define a lens potential and the deflection angles will be computed from it's gradient, and the convergence will be computed from the hessian. Also, implemented better version of the jacobian of the deflection angles.

@ConnorStoneAstro
Copy link
Member Author

This may also address #242

Copy link

codecov bot commented Dec 20, 2024

Codecov Report

Attention: Patch coverage is 96.66667% with 2 lines in your changes missing coverage. Please review.

Project coverage is 91.91%. Comparing base (bf26a57) to head (ed082ec).
Report is 33 commits behind head on dev.

Files with missing lines Patch % Lines
src/caustics/lenses/base.py 92.30% 1 Missing ⚠️
src/caustics/lenses/tnfw.py 88.88% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##              dev     #306      +/-   ##
==========================================
+ Coverage   91.19%   91.91%   +0.72%     
==========================================
  Files          55       55              
  Lines        2306     2277      -29     
==========================================
- Hits         2103     2093      -10     
+ Misses        203      184      -19     
Flag Coverage Δ
unittests 91.91% <96.66%> (+0.72%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ConnorStoneAstro ConnorStoneAstro changed the title better use of autograd for base lens quantities refactor: better use of autograd for base lens quantities Dec 20, 2024
@ConnorStoneAstro ConnorStoneAstro added the refactor A code change that neither fixes a bug nor adds a feature label Dec 20, 2024
Copy link
Collaborator

@AlexandreAdam AlexandreAdam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NFW and tNFW not passing the test for potential. Any idea why that is?

@ConnorStoneAstro
Copy link
Member Author

NFW and tNFW not passing the test for potential. Any idea why that is?

Ah, that was because I made the new thin lens default reduced deflection angle compute the gradient of the potential (rather than cyclic definition with physical deflection angle). The way that calculation is done involves a vmap, and NFW/TNFW cant do both vmap and autograd. Nothing changed about NFW/TNFW, they still work, just the test now uses vmap and autograd rather than a very large autograd call.

@ConnorStoneAstro
Copy link
Member Author

Posting here the improvements to TNFW. Now works with autodif and vmap (NFW now has this too). Also, better handling of F function, is arccosh for 0<x<1-epsilon and is arccos for 1+epsilon<x, for x=1+-epsilon we use taylor expansion to get correct first and second derivatives. in the images below we compare several approximations where F_arccosh is the adopted approximation.
TNFW_F

TNFW_dF

TNFW_d2F

Copy link
Collaborator

@mjyb16 mjyb16 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like a great improvement! I presume the #fixme comment in _P_tnfw is fixed now?

@ConnorStoneAstro ConnorStoneAstro merged commit ac2c427 into dev Jan 25, 2025
12 of 13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactor A code change that neither fixes a bug nor adds a feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fix circular logic in Thin Lens deflection angle calculation for multiplane code
3 participants